#import "MorePlusThanMinus.h"

@interface MorePlusThanMinus ()

@property NSArray* colors;
@property BOOL isGameOver;
@property NSInteger numberOfPlus;
@property NSInteger numberOfMinus;

@end

@implementation MorePlusThanMinus

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setName:@"MorePlusThanMinus"];
        [self setType:reaction];
        self.ruleOfTheGame=@"Hit when plus is more than minus";
        
        
        self.colors=[[NSArray alloc]initWithObjects:@"blue",@"white",@"red",@"yellow",@"orange",@"purple",@"green", nil];
        
    }
    return self;
}


-(void)draw{
    [self removeAllComponents];
    
    self.numberOfMinus=0;
    self.numberOfPlus=0;
    
    for (int coloum=0; coloum<10; coloum++) {
        for (int row=0; row<10; row++) {
            NSInteger imageSize=(kScreenHeight-2*kButtonHeigh-kWidthMargin)/10;
            int sign=arc4random_uniform(2);
            if (sign == 0) {
                ImageGameComponent* image=[[ImageGameComponent alloc]initWithName:@"plus.png" andFrame:CGRectMake(kHeighMargin+(coloum*imageSize), kWidthMargin+(row*imageSize), imageSize, imageSize)andTrans:0];
                [self addComponents:image];
                self.numberOfPlus++;
            }
            else{
                ImageGameComponent* image=[[ImageGameComponent alloc]initWithName:@"minus.png" andFrame:CGRectMake(kHeighMargin+(coloum*imageSize), kWidthMargin+(row*imageSize), imageSize, imageSize)andTrans:0];
                [self addComponents:image];
                self.numberOfMinus++;
            }
            
        }
    }
    
    
    
}

-(BOOL)isRight{
    return (self.numberOfPlus > self.numberOfMinus);
}

-(void)play{
    [self draw];
    
     [NSTimer scheduledTimerWithTimeInterval: 2                                                 target: self selector:@selector(newFace:)userInfo: nil repeats:YES];
    
}

-(void)newFace:(NSTimer*)timer{
    if (self.isGameOver==YES) {
        [timer invalidate];
    }
    else{
        [self draw];
        
        [[NSNotificationCenter defaultCenter]postNotificationName:@"SomeGames" object:self userInfo:nil];
        
    }
    
}

-(void)gameOver{
    self.isGameOver=YES;
}

@end
